<?php

use yii\helpers\Html;
use yii\grid\GridView;
use common\models\business\BusinessContract;
use yii\helpers\ArrayHelper;
use yii\web\JsExpression;

/* @var $this yii\web\View */
/* @var $searchModel backend\modules\business\models\BusinessPigFileSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = '仔猪档案管理';
$this->params['breadcrumbs'][] = $this->title;
?>


<section class="wrapper site-min-height">
    <!-- page start-->
    <section class="panel">
        <header class="panel-heading">
              <?= Html::a('返回','javascript:history.back(-1)'); ?>  <?= Html::encode($this->title) ?>
        </header>
        <div class="panel-body">
            <div class="adv-table editable-table ">
 


<div class="business-pig-file-index">

    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>

    <p>
        <?= Html::a('添加档案', ['create'], ['class' => 'btn btn-success']) ?>
    </p>


        <?php
            echo \kartik\grid\GridView::widget([
                'dataProvider'=>$dataProvider,
                'filterModel'=>$searchModel,
                'showPageSummary'=>true,
                'pjax'=>true,
                'striped'=>true,
                'hover'=>true,
                'panel'=>['type'=>'primary', 'heading'=>'档案管理'],
                'containerOptions'=>['style'=>'overflow: auto'], // only set when $responsive = false
                'headerRowOptions'=>['class'=>'kartik-sheet-style'],
                'filterRowOptions'=>['class'=>'kartik-sheet-style'],
                'columns'=>[
                    [
                        'attribute'=>'no',
                        'pageSummaryOptions'=>['class'=>'text-right text-warning'],
                        'width'=>'100px',
                    ],
                    [
                        'attribute'=>'name',
                        'pageSummaryOptions'=>['class'=>'text-right text-warning'],
                        'width'=>'100px',
                    ],
                    [
                        'attribute'=>'father',
                        'pageSummaryOptions'=>['class'=>'text-right text-warning'],
                        'width'=>'100px',
                    ],
                    [
                        'attribute'=>'mathor',
                        'pageSummaryOptions'=>['class'=>'text-right text-warning'],
                        'width'=>'100px',
                    ],
                    [
                        'attribute'=>'variety',
                        'width'=>'100px',
                        'format' => 'raw',
                        'value' => function($model){
                            return $model->varietyname?Html::a($model->varietyname->title,\yii\helpers\Url::to(['/business/variety/view','id'=>$model->varietyname->id])):'(未设置)';
                        },
                        'filterType'=>\kartik\grid\GridView::FILTER_SELECT2,
                        'filter'=>ArrayHelper::map(\common\models\business\BusinessVariety::find()->asArray()->all(),'id','title'),
                        'filterWidgetOptions'=>[
                            'pluginOptions'=>['allowClear'=>true],
                        ],
                        'filterInputOptions'=>['placeholder'=>'选择品种'],
                    ],
                    [
                        'attribute'=>'constract_id',
                        'width'=>'100px',
                        'format' => 'raw',
                        'value' => function($model){
                            return $model->constract?Html::a($model->constract->name,\yii\helpers\Url::to(['/business/contract/view','id'=>$model->constract->id])):'(未设置)';
                        },
                        'filterType'=>\kartik\grid\GridView::FILTER_SELECT2,
                        'filter'=>ArrayHelper::map(BusinessContract::find()->asArray()->all(),'id','name'),
                        'filterWidgetOptions'=>[
                            'options' => ['placeholder' => '请输入合同名称...'],
                            'pluginOptions' => [
                                'allowClear' => true,
                                'minimumInputLength' => 1,//重要
                                'language' => [
                                    'errorLoading' => new JsExpression("function () { return 'Waiting...'; }"),
                                ],
                                'ajax' => [
                                    'url' => '/business/search/search-contract',
                                    'dataType' => 'json',
                                    'data' => new JsExpression('function(params) { return {q:params.term}; }'),
                                    'cache' => true
                                ],
                                'width' => '400px',
                                'escapeMarkup' => new JsExpression('function (markup) { return markup;}'),
                                'templateResult' => new JsExpression('function(res) { return res.text;}'),
                                'templateSelection' => new JsExpression('function (res) { return res.text;}'),
                            ],
                        ],
                        'filterInputOptions'=>['placeholder'=>'选择合同'],
                    ],
                    [
                        'class' => '\kartik\grid\CheckboxColumn'
                    ],
                    [
                    'class' => '\kartik\grid\ActionColumn',
                    'deleteOptions' => ['label' => '<i class="glyphicon glyphicon-remove"></i>'],
                    ],
                ],
                'toolbar'=> [
                    ['content'=>
                        Html::button('<i class="glyphicon glyphicon-plus"></i>', ['type'=>'button', 'title'=>'选中归为档案', 'class'=>'btn btn-success', 'onclick'=>'alert("This will launch the book creation form.\n\nDisabled for this demo!");'])
                    ],
                    '{export}',
                    '{toggleData}',
                ],
                'bordered'=>true,
                'condensed'=>true,
            ]);
            ?>

</div>
</div>
</div>
</section>
</section>



